#pragma once

#include "iostream"

using namespace std;

struct char_map_node
{
	char_map_node(const char* key, const char* value)
	{
		int key_size = strlen(key) + 1;
		int value_size = strlen(value) + 1;
		this->m_key = new char[key_size];
		this->m_value = new char[value_size];

		strcpy_s(this->m_key, key_size, key);
		strcpy_s(this->m_value, value_size, value);

		m_next = 0;
		m_prev = 0;
	}

	~char_map_node()
	{
		delete[] m_key;
		delete[] m_value;
		m_key = 0;
		m_value = 0;
		m_next = 0;
		m_prev = 0;
	}

	void set_value(const char* value)
	{
		delete[] m_value;
		int value_size = strlen(value) + 1;
		this->m_value = new char[value_size];
		strcpy_s(this->m_value, value_size, value);
	}

	char* m_key;
	char* m_value;
	char_map_node* m_next;
	char_map_node* m_prev;
};

class char_map
{
public:
	char_map();
	~char_map();

public:
	int set(const char* key, const char* value);
	void clear();
	const char* operator[](const char* key);
	const char* get(int index);
	int get_count();

	void show();

protected:
	char_map_node* find(const char* key);

private:
	char_map_node* m_head;
	char_map_node* m_tail;

	int m_count;
};

